package com.pri.chat.adapter;

import android.graphics.Color;
import android.media.Image;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.SharedHelper;
import com.netease.nim.uikit.net.entity.WishRecordBean;
import com.pri.chat.R;
import com.pri.chat.view.ImageViewPlus;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author
 * @time 2020/4/28
 */
public class WishAllRecordAdapter extends BaseQuickAdapter<WishRecordBean, BaseViewHolder> {
    private String dtMemberId;
    public WishAllRecordAdapter(int layoutResId, @Nullable List<WishRecordBean> data,String dtMemberId) {
        super(layoutResId, data);
        this.dtMemberId = dtMemberId;
    }

    @Override
    protected void convert(BaseViewHolder helper, WishRecordBean item) {
        helper.setText(R.id.tv_comment_time,item.getAddDate());
        helper.addOnClickListener(R.id.iv_logo);
        helper.addOnClickListener(R.id.tv_status);
        helper.addOnClickListener(R.id.btn_jujue);
        helper.addOnClickListener(R.id.btn_tongyi);
        helper.setText(R.id.tv_dt_age,item.getAge());
        TextView status = helper.getView(R.id.tv_status);

        TextView tongyi = helper.getView(R.id.btn_tongyi);
        TextView jujue = helper.getView(R.id.btn_jujue);

        String memberId = SharedHelper.readId(mContext);

        if(item.getStatus()==0){
            helper.setText(R.id.tv_status,"已接单");
            helper.setVisible(R.id.tv_status,false);
            status.setTextColor(Color.parseColor("#02CFA5"));
            if(dtMemberId.equals(memberId)){
                tongyi.setVisibility(View.VISIBLE);
                jujue.setVisibility(View.VISIBLE);
            }else{
                tongyi.setVisibility(View.GONE);
                jujue.setVisibility(View.GONE);
            }
        }else   if(item.getStatus()==1){
            helper.setText(R.id.tv_status,"实现中");
            helper.setVisible(R.id.tv_status,true);
            status.setTextColor(Color.parseColor("#3B89F8"));
            if(memberId.equals(item.getMemberId())){
                tongyi.setText("完成");
                tongyi.setVisibility(View.VISIBLE);
                jujue.setVisibility(View.GONE);
            }else{
                tongyi.setVisibility(View.GONE);
                jujue.setVisibility(View.GONE);
            }
        }else if(item.getStatus()==2){
            tongyi.setText("确定");
            helper.setVisible(R.id.tv_status,true);
            status.setTextColor(Color.parseColor("#049A30"));
            if(dtMemberId.equals(memberId)){
                tongyi.setVisibility(View.VISIBLE);
                helper.setText(R.id.tv_status,"对方已帮您完成");
            }else{
                tongyi.setVisibility(View.GONE);
                helper.setText(R.id.tv_status,"已完成，等待对方确认");
            }
            jujue.setVisibility(View.GONE);
        }else if(item.getStatus()==21){
            helper.setText(R.id.tv_status,"已完成");
            helper.setVisible(R.id.tv_status,true);
            status.setTextColor(Color.parseColor("#049A30"));
            tongyi.setVisibility(View.GONE);
            jujue.setVisibility(View.GONE);
        }else if(item.getStatus()==3){
            helper.setText(R.id.tv_status,"已拒绝");
            helper.setVisible(R.id.tv_status,true);
            status.setTextColor(Color.parseColor("#999999"));
            tongyi.setVisibility(View.GONE);
            jujue.setVisibility(View.GONE);
        }
        View sex_bg = helper.getView(R.id.sex_bg);
        ImageView sex_logo = helper.getView(R.id.sex_logo);
        if("男".equals(item.getSex())){
            sex_logo.setImageResource(R.mipmap.man);
            sex_bg.setBackgroundResource(R.drawable.btn_sex_man);
        }else{
            sex_logo.setImageResource(R.mipmap.man);
            sex_bg.setBackgroundResource(R.drawable.btn_sex_woman);
        }

        helper.setText(R.id.tv_comment_name,item.getMemberName());
        Glide.with(mContext).load(item.getHeadPic()).into((ImageViewPlus)helper.getView(R.id.iv_logo));
    }
}
